﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 设计模式.享元模式
{
    public class FlyweightPatternDemo
    {
        private static string[] colors = new string[] { "Red", "Green", "Blue", "White", "Black" };

        public static void Test()
        {
            

            for(int i = 0; i < 20; i++)
            {
                Circle circle = (Circle)ShapeFactory.GetCircle(RandomColor);
                circle.X = RandomX;
                circle.Y = RandomY;
                circle.Radius = 100;
                circle.Draw();
            }
        }

        private static string RandomColor
        {
            get
            {
                return colors[new Random().Next(0, colors.Length)];
            }
        }

        private static int RandomX
        {
            get
            {
                return new Random().Next(101);
            }
        }

        private static int RandomY
        {
            get
            {
                return new Random().Next(101);
            }
        }
    }
}
